﻿using System;
using System.Data;
using DevExpress.Web.ASPxTreeView;
using DevExpress.XtraCharts;

namespace openMap
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MapService mapService = new MapService();
            
        }

        protected void initialTreeView()
        {
            treeView.Nodes.Clear();

            string sql = "Select year from webTest.Test group by year";

            //DataTable dataTable = MapService.dataBaseHelper.GetDataTable(sql);
            //foreach (DataRow dataRow in dataTable.Rows)
            //{
            //    string value = dataRow[0].ToString();
            //    TreeViewNode node = new TreeViewNode(value, value);
            //    treeView.Nodes.Add(node);
            //}

            treeView.ExpandAll();
        }

        protected void InitialChartData(string year)
        {
            webChart.Titles.Clear();
            ChartTitle newTitle = new ChartTitle { Text = year + " 数据" };
            webChart.Titles.Add(newTitle);

            Series series = webChart.Series["Series1"];
            if (series != null)
            {
                if (series.Points.Count > 0)
                    series.Points.Clear();

                DataTable dataTable = new DataTable();
                   //MapService.dataBaseHelper.GetDataTable("Select month,value from webTest.Test where year = " + year);
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    foreach (DataRow dataRow in dataTable.Rows)
                    {
                        Int32 month = Convert.ToInt32(dataRow[0]);
                        Int32 value = Convert.ToInt32(dataRow[1]);

                        var seriesPoint = new SeriesPoint(month, value);

                        series.Points.Add(seriesPoint);
                    }
                }
            }
        }
        protected void treeView_NodeClick(object source, TreeViewNodeEventArgs e)
        {
            string year = e.Node.Name;

            InitialChartData(year);
        }
    }
}